<template>
  <div class="app-container">
   <!-- <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="80px">
      <el-form-item label="关键词" prop="searchtxt">
        <el-input
          v-model="queryParams.searchtxt"
          placeholder="请输入关键词"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['system:activity:add']"
        >新增</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleUpdate"
          v-hasPermi="['system:activity:edit']"
        >修改</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          v-hasPermi="['system:activity:remove']"
        >删除</el-button>
      </el-col>
      <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
    </el-row>
  -->

    <el-table v-loading="loading" :data="userList" @selection-change="handleSelectionChange">
      <!-- <el-table-column type="selection" width="55" align="center" /> -->
      <el-table-column label="序号" align="center" type="index" width="50" />
      <el-table-column label="账号" align="center" prop="enterpriseContactPhone" />
      <!-- TODO -->
      <el-table-column label="评论律师" align="center" prop="enterpriseFullname" />
      <el-table-column label="提交时间" align="center" prop="createdAt" width="180">
        <template slot-scope="scope">
          {{ parseTime(scope.row.createTime) }}
        </template>
      </el-table-column>
      <el-table-column label="操作" align="center" class-name="small-padding fixed-width">
        <template slot-scope="scope">
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
          >查看</el-button>
          <el-button
            size="mini"
            type="text"
            icon="el-icon-check"
            @click="handleApprove(scope.row)"
          >审核通过</el-button>
          <!-- <el-button
            size="mini"
            type="text"
            class="text-red"
            icon="el-icon-remove-outline"
            @click="handleDelete(scope.row)"
          >删除</el-button> -->
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />

    <!-- 添加或修改【请填写功能名称】对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="780px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="180px">

        <el-form-item label="是否合作过该律师" prop="isbizval">
          <el-select v-model="form.isbizval" placeholder="请选择">
             <el-option label="否" :value="0"></el-option>
             <el-option label="是" :value="1"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="律师的业务类型" prop="expertJoblevel">
          <el-select v-model="form.expertJoblevel" placeholder="请选择">
             <el-option label="诉讼" value="诉讼"></el-option>
             <el-option label="非诉" value="非诉"></el-option>
             <el-option label="两者均做" value="两者均做"></el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="与TA合作在哪一年" prop="commentYear">
          <el-input v-model="form.commentYear" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="合作所涉及的业务领域" prop="commentTerritory">
          <el-input v-model="form.commentTerritory" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="专业水平" prop="scoreStartone1">
          <el-input disabled v-model="form.scoreStartone1" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="行业经验" prop="scoreStartone2">
          <el-input disabled v-model="form.scoreStartone2" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="沟通能力" prop="scoreStartone3">
          <el-input disabled v-model="form.scoreStartone3" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="文书水平" prop="scoreStartone4">
          <el-input disabled v-model="form.scoreStartone4" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="响应速度" prop="scoreStartone5">
          <el-input disabled v-model="form.scoreStartone5" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="资源统筹" prop="scoreStartone6">
          <el-input disabled v-model="form.scoreStartone6" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="工作效率" prop="scoreStartone7">
          <el-input disabled v-model="form.scoreStartone7" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="服务意识" prop="scoreStartone8">
          <el-input disabled v-model="form.scoreStartone8" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="商务经验" prop="scoreStartone9">
          <el-input disabled v-model="form.scoreStartone9" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="工作成果" prop="scoreStartone10">
          <el-input disabled v-model="form.scoreStartone10" placeholder="请输入" />
        </el-form-item>

        <el-form-item label="评价语" prop="commentCon">
          <el-input v-model="form.commentCon" type="textarea" :rows="3" placeholder="请输入" />
        </el-form-item>

      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import { queryList, getItem, delItem, addItem, updateItem } from "@/api/official/comment"

export default {
  name: "User",
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 【请填写功能名称】表格数据
      userList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        isCheck: 0,
        searchtxt: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
      },
      imgAction: `${process.env.VUE_APP_BASE_API}/common/ftpftpCommonUpload`,
    }
  },
  created() {
    this.getList()
  },
  methods: {
    /** 查询【请填写功能名称】列表 */
    getList() {
      this.loading = true
      queryList(this.queryParams).then(response => {
        this.userList = response.rows
        this.total = response.total
        this.loading = false
      })
    },
    // 取消按钮
    cancel() {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        openid: null,
        avatar: null,
        nickname: null,
        realname: null,
        userLevel: null,
        cheese: null,
        integral: null,
        phone: null,
        lawyerJoblevel: null,
        isAdmin: null,
        sort: null,
        status: null,
        createdAt: null,
        updatedAt: null
      }
      this.resetForm("form")
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1
      this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm")
      this.handleQuery()
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length!==1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset()
      this.open = true
      this.title = "添加信息"
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset()
      const id = row.id || this.ids
      getItem(id).then(response => {
        this.form = response.data
        this.open = true
        this.title = `修改信息`
      })
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != null) {
            updateItem(this.form).then(response => {
              this.$modal.msgSuccess("修改成功")
              this.open = false
              this.getList()
            })
          } else {
            addItem(this.form).then(response => {
              this.$modal.msgSuccess("新增成功")
              this.open = false
              this.getList()
            })
          }
        }
      })
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      this.$modal.confirm('是否确认删除【信息编号为"' + ids + '"的数据项？').then(function() {
        return delItem(ids)
      }).then(() => {
        this.getList()
        this.$modal.msgSuccess("删除成功")
      }).catch(() => {})
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download('system/user/export', {
        ...this.queryParams
      }, `user_${new Date().getTime()}.xlsx`)
    },
    // 状态修改
    handleStatusChange(row, field='status') {
      let text = row[field] == 0 ? "停用" : "启用"
      this.$modal.confirm(`确认要"${text}"该企业吗？`).then(function() {
        return updateItem({id :row.id, [field]: row[field]})
      }).then(() => {
        this.$modal.msgSuccess(text + "成功")
      }).catch(function() {
        row[field] = row[field] == "0" ? 1 : 0
      })
    },
    // 审核
    handleApprove(row) {
      this.$modal.confirm(`确认要"通过"该评论吗？`).then(function() {
        return updateItem({id :row.id, isCheck: 1})
      }).then(() => {
        this.$modal.msgSuccess("操作成功")
      })
    },
    beforeUpload(file) {
      let isRightSize = file.size / 1024 / 1024 < 5
      if (!isRightSize) {
        this.$message.error('文件大小超过 5MB')
      }
      let isAccept = new RegExp('image/*').test(file.type)
      if (!isAccept) {
        this.$message.error('应该选择image/*类型的文件')
      }
      return isRightSize && isAccept
    },
    uploadSuccess(res){
      this.form.officeImages = res.path;
    }
  }
}
</script>

<style scoped>
.more-radio-group .el-radio{
  margin-top: 10px;
}
.other-input {
  margin-top: 8px;
}
</style>
